package com.huterox.todoscheduler.core.execute.proxy;

import com.huterox.todoscheduler.core.enumType.TodoListElementType;
import com.huterox.todoscheduler.core.enumType.TodoListStateType;
import com.huterox.todoscheduler.core.wapper.ListStateWrapper;
import com.huterox.todoscheduler.handler.*;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * 任务清单对象，这里记录的是基本的清单对象信息，
 * */
public class TodoListExBean implements Serializable {

    //任务清单类型
    public TodoListElementType todoListElementType;

    //任务清单的名字
    public String todoListName;

    //当前的状态，当然服务宕机恢复任务的时候，这个是一个很重要的凭证
    public TodoListStateType todoListStateType;

    //任务清单的状态信息
    private ListStateWrapper stateWrapper;

    //执行的次数，因为有失败重新执行的东东
    private int exTimes;



    /*
    * 因为几个清单可能服务同一个用户，所以按照这个再给你分个类
    * 对于ClsId相同的清单是顺序执行的，所以这个是最小颗粒度的操作
    * */
    public String ClsId;
    TodoListErrorHandler todoListErrorHandler;
    TodoListAfterHandler todoListAfterHandler;
    TodoListBeforeCreateHandler todoListCreateCheckHandler;


    private final Comparator<Integer> keyComparator = new Comparator<Integer>() {
        @Override
        public int compare(Integer key1, Integer key2) {
            // 根据键的大小进行比较
            return key1.compareTo(key2);
        }
    };
    //对应执行的方法链路
    private final Map<Integer, TodoItemExBean> sortedMap = new TreeMap<>(keyComparator);

    public TodoListExBean() {
    }

    public TodoListExBean(TodoListElementType todoListElementType, String todoListName, TodoListErrorHandler todoListErrorHandler, TodoListAfterHandler todoListAfterHandler, TodoListBeforeCreateHandler todoListCreateCheckHandler) {
        this.todoListElementType = todoListElementType;
        this.todoListName = todoListName;
        this.todoListErrorHandler = todoListErrorHandler;
        this.todoListAfterHandler = todoListAfterHandler;
        this.todoListCreateCheckHandler = todoListCreateCheckHandler;
    }

    @Override
    public String toString() {
        return "The TodoList name is:"+this.todoListName;
    }

    public int getExTimes() {
        return exTimes;
    }

    public void setExTimes(int exTimes) {
        this.exTimes = exTimes;
    }

    public TodoListExBean(String todoListName) {
        this.todoListName = todoListName;
    }

    public TodoListStateType getTodoListStateType() {
        return todoListStateType;
    }



    public void setTodoListStateType(TodoListStateType todoListStateType) {
        this.todoListStateType = todoListStateType;
    }

    public ListStateWrapper getStateWrapper() {
        return stateWrapper;
    }

    public void setStateWrapper(ListStateWrapper stateWrapper) {
        this.stateWrapper = stateWrapper;
    }

    public Comparator<Integer> getKeyComparator() {
        return keyComparator;
    }

    public Map<Integer, TodoItemExBean> getSortedMap() {
        return sortedMap;
    }

    public TodoListExBean(String todoListName, String clsId) {
        this.todoListName = todoListName;
        ClsId = clsId;
    }

    public TodoListElementType getTodoListElementType() {
        return todoListElementType;
    }

    public void setTodoListElementType(TodoListElementType todoListElementType) {
        this.todoListElementType = todoListElementType;
    }

    public String getTodoListName() {
        return todoListName;
    }

    public String getClsId() {
        return ClsId;
    }

    public void setClsId(String clsId) {
        ClsId = clsId;
    }

    public void setTodoListName(String todoListName) {
        this.todoListName = todoListName;
    }

    public TodoListErrorHandler getTodoListErrorHandler() {
        return todoListErrorHandler;
    }

    public void setTodoListErrorHandler(TodoListErrorHandler todoListErrorHandler) {
        this.todoListErrorHandler = todoListErrorHandler;
    }

    public TodoListAfterHandler getTodoListAfterHandler() {
        return todoListAfterHandler;
    }

    public void setTodoListAfterHandler(TodoListAfterHandler todoListAfterHandler) {
        this.todoListAfterHandler = todoListAfterHandler;
    }

    public TodoListBeforeCreateHandler getTodoListCreateCheckHandler() {
        return todoListCreateCheckHandler;
    }

    public void setTodoListCreateCheckHandler(TodoListBeforeCreateHandler todoListCreateCheckHandler) {
        this.todoListCreateCheckHandler = todoListCreateCheckHandler;
    }


}
